<%--
  Created by IntelliJ IDEA.
  User: xiaodoudou
  Date: 2020/11/1
  Time: 10:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<%String path = request.getContextPath();%>
<form action="/user/login" method="post" id="myform">

    <div class="form_text_ipt">
        <input id="username" name="name" type="text" placeholder="用户名">
        <span></span>
    </div>

    <div class="form_text_ipt">
        <input id="password" name="password" type="password" placeholder="密码">
        <span></span>
    </div>

    <div  style="margin-left:25px;margin-top: 20px" id="verify_type1"></div>

    <div class="form_check_ipt">
        <div class="left check_left">
            <label><input name="remberMe" type="checkbox"> 下次自动登录</label>
        </div>
        <div class="right check_right">
            <a href="#">忘记密码</a>
        </div>
    </div>
    <div class="form_btn">
        <button type="button" id="login">登录</button>
    </div>
    <div class="form_reg_btn">
        <span>还没有帐号？</span><a href="<%=path%>/user/registe">马上注册</a>
    </div>
</form>

<!--滑块验证-->
<script type="text/javascript">



    var flag = false;
    $(function () {
        sliding();
    })

    function sliding()
    {
        var type1 = document.getElementById('verify_type1');
        verifyFun.bar({
            dom:type1,		// dom对象
            width:'300',	// 盒子宽
            height:'40',	// 盒子高
            hsize:'15',		// 提示字体大小
            size:'20',		// 滑动块箭头字体大小
            diff:5,			// 误差值
            success:function() {
                flag = true;
            },
            error:function() {
                flag = false;
            }
        });
        return flag;
    }
</script>

<script>
    $(function () {
        //失去焦点验证
        $("#username").blur(checkUsername);
        $("#username").focus(function () {
            $("#username").next().html("");
        })
        //失去焦点验证密码
        $("#password").blur(checkPassword);
        $("#password").focus(function () {
            $("#password").next().html("");
        })

        //表单提交
        $("#login").click(submit);



        //验证用户名
        function checkUsername() {
            var username = $("#username").val();
            var flag = false;
            if(username=="") {
                $("#username").next().html("用户名不能为空呦~");
                $("#username").next().css("color","red");
                return flag=false;
            }
            return flag = true;
        }

        //验证密码
        function checkPassword() {
            var password = $("#password").val();
            var flag = false;
            if(password==""){
                $("#password").next().html("密码不能为空呦~");
                $("#password").next().css("color","red");
                return flag=false;
            }
            return flag = true;
        }

        //表单验证
        function submit() {
            var flag1 = checkUsername();
            var flag2 = checkPassword();
            var flag3 = sliding();
            var username = $("#username").val();
            var password = $("#password").val();
            if(flag1&&flag2&&flag3){
                //验证用户名密码是否正确
                $.ajax({
                    url:"<%=path%>/isRegiste",
                    async:false,
                    data:{"name":username,"password":password},
                    type:"post",
                    success:function (mes) {
                        //用户名密码不对或者没有注册
                        if(mes=="true"){
                            alert("用户名或者密码不对呦~");
                            return false;
                        }
                        if(mes=="false"){
                            $("#myform").submit();

                        }
                    }
                })//ajax结束
            }
        }


    })//网页加载函数结束
</script>